import { _decorator, Collider2D, Component, Node, Contact2DType, Animation, PhysicsSystem2D, Label, Vec3, BoxCollider2D, tween, UIOpacity, EPhysics2DDrawFlags, RigidBody2D, sys } from 'cc';
import DataManager from './DataManager';
import { DIRECTION_ENUM, EAT_STATUS_ENUM, GAME_MODE_ENUM, PARAME_NAME_ENUM, PLAYER_ENUM, SOCKET_TYPE } from '../../Enums';
import { BombManager } from '../Property/BombManager';
import { ExplosionTimingManager } from '../Property/ExplosionTimingManager';
import { LurkerManager } from '../Property/LurkerManager';
import { PlayManager } from '../Player/PlayManager';
import { GamePlayer } from '../Role/GamePlayer';
import { StoneManager } from '../Property/StoneManager';
import { JellyManager } from '../Property/JellyManager';
import { HeavyManager } from '../Property/HeavyManager';
import { BrickManager } from '../Property/BrickManager';
import { GameElement } from '../UI/GameElement';
import { createPlaceholder, createUILabel, createUINode, destroyNode, getEnemyManager, getPropertyManager, getRandomNumber, getSendId, roundToNearestInteger } from '../utils';
import { sendSocket, useSocket } from '../service/socket';
const { ccclass } = _decorator;
const socket = useSocket();
@ccclass('CollisionDetection')
export class CollisionDetection extends Component {
    controllerManager: any;
    brickAttackList: Array<Node> = []
    blue_timeout = null
    green_timeout = null
    init({ controllerManager }) {
        this.controllerManager = controllerManager
        // PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape;
        if (PhysicsSystem2D.instance) {
            PhysicsSystem2D.instance.on(
                Contact2DType.BEGIN_CONTACT,
                this.onBeginContact,
                this
            );

            PhysicsSystem2D.instance.on(
                Contact2DType.END_CONTACT,
                this.onEndContact,
                this
            );
        }
    }

    // 开始触碰
    async onBeginContact(self: Collider2D, other: Collider2D,) {
        // 设置游戏层级
        if (other.node.name.includes(`sensor`) || self.node.name.includes(`sensor`)) {
            let { selfNode, otherNode, } = this.assortSelfAndOther({ name: "sensor", self, other })
            let siblingIndex = selfNode.getSiblingIndex()
            if (siblingIndex < DataManager.Instance.low_level) {
                siblingIndex = Number(selfNode.name.split("-")[3])
            }
            if (otherNode.name.includes("enemy")) {
                let enemy = otherNode.getComponent(getEnemyManager(otherNode))
                if (enemy.fly) {
                    otherNode?.setSiblingIndex(9999)
                } else {
                    otherNode?.setSiblingIndex(siblingIndex)
                }
            } else {
                otherNode?.setSiblingIndex(siblingIndex)
            }
        }
        // 角色碰撞
        if (other.node.name.includes(`role`) || self.node.name.includes(`role`)) {
            let { selfNode, otherNode, otherNodeName, } = this.assortSelfAndOther({ name: "role", self, other })
            let playManager = selfNode.getChildByName("role").getChildByName("userNode").getComponent(PlayManager)
            let { direction } = playManager
            // 踩到滑块
            if (otherNodeName.includes('slide')) {
                let gamePlayer = selfNode.getComponent(GamePlayer)
                // 如果前方有障碍物就停下
                if (gamePlayer.physicsRaycast(true)) {
                    playManager.forcedWalking = false
                    return
                }
                playManager.forcedWalking = true
                if (sys.isMobile) {
                    if (playManager.type == PLAYER_ENUM.GREEN) {
                        if (this.green_timeout) {
                            clearTimeout(this.green_timeout)
                            this.green_timeout = null
                        }
                    } else {
                        if (this.blue_timeout) {
                            clearTimeout(this.blue_timeout)
                            this.blue_timeout = null
                        }
                    }
                }
                if (playManager.state != PARAME_NAME_ENUM.DIZZY && playManager.state != PARAME_NAME_ENUM.WIN) {
                    playManager.state = PARAME_NAME_ENUM.IDLE
                }
                if (direction == DIRECTION_ENUM.TOP) {
                    playManager.targetY = roundToNearestInteger(otherNode.getPosition().y + DataManager.Instance.position)
                } else if (direction == DIRECTION_ENUM.BOTTOM) {
                    playManager.targetY = roundToNearestInteger(otherNode.getPosition().y - DataManager.Instance.position)
                } else if (direction == DIRECTION_ENUM.LEFT) {
                    playManager.targetX = roundToNearestInteger(otherNode.getPosition().x - DataManager.Instance.width)
                } else if (direction == DIRECTION_ENUM.RIGHT) {
                    playManager.targetX = roundToNearestInteger(otherNode.getPosition().x + DataManager.Instance.width)
                }
            }
            // 踩到了踩到才会触发的地刺
            if (otherNodeName.includes('children_lurker')) {
                let lurkerManager = otherNode.parent.getComponent(LurkerManager)
                lurkerManager.touchNode.push(selfNode)
                if (otherNodeName.includes('Touch')) {
                    if (lurkerManager.status == 0) {
                        let animation = otherNode.getComponent(Animation)
                        animation.play()
                    }
                }

            }
            if (otherNodeName.includes("enemy")) {
                let enemy = otherNode.getComponent(getEnemyManager(otherNode))
                if (enemy.dizzy || enemy.avoid) {
                } else {
                    selfNode.getComponent(GamePlayer).characterDeath()
                }
            }
        }
        // 爆炸判定
        if (other.node.name.includes(`blastStart`) || self.node.name.includes(`blastStart`)) {
            let { otherNode, otherNodeName, } = this.assortSelfAndOther({ name: "blastStart", self, other })
            // 忽略掉墙壁和层级传感器和自身
            let filterName = ['sensor', 'lurker', 'slide', 'wall']
            if (!filterName.find(item => otherNodeName.includes(item))) {
                if (otherNodeName.includes('bomb')) {
                    const explosionTimingManager = otherNode.getComponent(ExplosionTimingManager)
                    explosionTimingManager.blast()
                } else {
                    // 如果是在角色身上爆炸的,就判定死亡
                    if (otherNodeName.includes("role")) {
                        // 死亡逻辑
                        otherNode.getComponent(GamePlayer).characterDeath()
                        // console.log("角色死亡")
                    } else {
                        if (otherNodeName.includes('enemy')) {
                            let index = DataManager.Instance.enemyList.findIndex(item => item.node.uuid == otherNode.uuid)
                            if (index != -1) {
                                DataManager.Instance.enemyList.splice(index, 1)
                                if (DataManager.Instance.enemyList.length == 0) {
                                    if (DataManager.Instance.gameMode != GAME_MODE_ENUM.ONLINE) {
                                        if (!DataManager.Instance.levelInfo.nextLevel) {
                                            otherNode.parent.parent.getComponent(GameElement).createClearance()
                                        } else {
                                            otherNode.parent.parent.getComponent(GameElement).createAchieve()
                                        }
                                    } else {
                                        // socket通知游戏结束
                                        console.log("socket通知游戏结束")
                                        sendSocket(SOCKET_TYPE.SUCCESS, {})
                                    }
                                }
                            }
                        }
                        createPlaceholder(otherNode)
                        destroyNode(otherNode)
                    }
                }
            }
        }
        // 透明子弹 Prop道具
        if (other.node.name.includes(`nullAttack`) || self.node.name.includes(`nullAttack`)) {
            let { selfNode, otherNodeName, otherNode, } = this.assortSelfAndOther({ name: "nullAttack", self, other })
            //子弹忽略角色、位置传感器、墙、滑块、地刺的碰撞
            if (otherNodeName.includes("role") || otherNodeName.includes("slide") || otherNodeName.includes("sensor") || otherNodeName.includes("wall") || otherNodeName.includes("lurker")) {
                return
            }
            let playManager = selfNode.parent.getChildByName("userNode").getComponent(PlayManager)
            let parent = selfNode.parent
            // 水果不设置状态,增加分数
            if (otherNodeName.includes('fruit')) {
                this.setFractionNumber(parent, 50)
                createPlaceholder(otherNode)
                this.createAttackAnimation(otherNode, playManager)
            } else {
                DataManager.Instance.eatName = otherNodeName
                if (otherNodeName.includes("jelly")) {
                    let manager = otherNode.getComponent(getPropertyManager(otherNode))
                    if (!manager.is_running) {
                        playManager.eatFood = EAT_STATUS_ENUM.JELLY
                        this.createAttackAnimation(otherNode, playManager)
                    }
                }
                if (otherNodeName.includes("heavy")) {
                    let manager = otherNode.getComponent(getPropertyManager(otherNode))
                    if (!manager.is_running) {
                        playManager.eatFood = EAT_STATUS_ENUM.HEAVY
                        this.createAttackAnimation(otherNode, playManager)
                    }
                }
                if (otherNodeName.includes("bomb")) {
                    let manager = otherNode.getComponent(getPropertyManager(otherNode))
                    if (!manager.is_running) {
                        if (otherNode.getComponent(ExplosionTimingManager)) {
                            let remainingTime = otherNode.getComponent(ExplosionTimingManager).remainingTime
                            playManager.explosionTime = remainingTime == 0 ? 10 : remainingTime
                            DataManager.Instance.explosionTime = remainingTime
                        } else {
                            playManager.explosionTime = 10
                        }
                        const explosionTimingManager = parent.addComponent(ExplosionTimingManager)
                        explosionTimingManager.init(new Vec3(0, 160))
                        explosionTimingManager.playBombAnimation(true)
                        playManager.eatFood = EAT_STATUS_ENUM.BOMB
                        this.createAttackAnimation(otherNode, playManager)
                    }
                }
                if (otherNodeName.includes("stone")) {
                    let manager = otherNode.getComponent(getPropertyManager(otherNode))
                    if (!manager.is_running) {
                        playManager.eatFood = EAT_STATUS_ENUM.STONE
                        this.createAttackAnimation(otherNode, playManager)
                    }
                }
                if (otherNodeName.includes("brick")) {
                    let manager = otherNode.getComponent(getPropertyManager(otherNode))
                    if (!manager.is_running) {
                        playManager.eatFood = EAT_STATUS_ENUM.BRICK
                        this.createAttackAnimation(otherNode, playManager)
                    }
                }
            }
            // 消除透明子弹
            destroyNode(selfNode)
            if (otherNodeName.includes('enemy')) {
                let enemy = otherNode.getComponent(getEnemyManager(otherNode))
                // 如果怪物是晕倒的情况下，就能吃掉，否则就不行
                if (enemy.dizzy) {
                    // 消除当前的道具
                    this.enemyDizzyAttack(parent, otherNode, playManager)
                }
            }
        }
        // 石头
        if (other.node.name.includes(`stoneAttack`) || self.node.name.includes(`stoneAttack`)) {
            let { selfNodeName, selfNode, otherNode, otherNodeName } = this.assortSelfAndOther({ name: "stoneAttack", self, other })
            // 撞到怪物把怪物移动到空地
            let filterName = ['sensor', 'children_lurker', 'slide', "enemy"]
            if (!filterName.find(item1 => otherNodeName.includes(item1))) {
                this.setRigidBody2DType(selfNode, otherNode)
            }
            // 撞到怪物的话
            if (otherNodeName.includes('enemy')) {
                this.enemyDizzy(selfNode, otherNode)
            }
        }
        // 大石头
        if (other.node.name.includes(`heavyAttack`) || self.node.name.includes(`heavyAttack`)) {
            let { selfNode, otherNodeName, otherNode } = this.assortSelfAndOther({ name: "heavyAttack", self, other })
            let filterName = ['enemy', 'sensor', 'children_lurker', 'slide']
            if (!filterName.find(item1 => otherNodeName.includes(item1))) {
                this.setRigidBody2DType(selfNode, otherNode)
            }
            // 撞到怪物的话
            if (otherNodeName.includes('enemy')) {
                this.enemyDizzy(selfNode, otherNode)
            }
        }
        // 砖头
        if (other.node.name.includes(`brickAttack`) || self.node.name.includes(`brickAttack`)) {
            let { selfNode, otherNodeName, otherNode } = this.assortSelfAndOther({ name: "brickAttack", self, other })
            let filterName = ['sensor', 'lurker']
            if (!filterName.find(item1 => otherNodeName.includes(item1))) {
                // 防止出现碰到多个物体动画重复的问题
                if (!otherNodeName.includes('jelly')) {
                    this.playBrickAttack(selfNode)
                    DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1231'))
                }
                if (otherNodeName.includes("brick")) {
                    console.log("砖块撞砖块")
                    this.playBrickAttack(otherNode)
                    DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1231'))
                }
                this.setRigidBody2DType(selfNode, otherNode)
            }
            // 撞到怪物的话
            if (otherNodeName.includes('enemy')) {
                this.enemyDizzy(selfNode, otherNode)
            }
        }
        // 果冻
        if (other.node.name.includes(`jellyAttack`) || self.node.name.includes(`jellyAttack`)) {
            let { selfNode, selfNodeName, otherNodeName, otherNode, } = this.assortSelfAndOther({ name: "jellyAttack", self, other })
            if (!otherNodeName.includes("sensor") && !otherNodeName.includes("lurker")) {
                // 播放果冻动画
                const animation = selfNode.getComponent(Animation)
                animation.play()
                if (otherNodeName.includes(`jelly`)) {
                    const animation = otherNode.getComponent(Animation)
                    animation.play()
                }
                let filterName = ['enemy', 'sensor', 'children_lurker', 'slide']
                if (!filterName.find(item1 => otherNodeName.includes(item1))) {
                    this.setRigidBody2DType(selfNode, otherNode)
                }
            }
            // 撞到怪物的话
            if (otherNodeName.includes('enemy')) {
                this.enemyDizzy(selfNode, otherNode)
            }
        }
        // 炸弹
        if (other.node.name.includes(`bombAttack`) || self.node.name.includes(`bombAttack`)) {
            let { selfNode, otherNodeName, otherNode } = this.assortSelfAndOther({ name: "bombAttack", self, other })
            selfNode.getComponent(BombManager).getComponent(ExplosionTimingManager).playBombAnimation()
            // 忽略掉和传感器的碰撞
            let filterName = ['enemy', 'sensor', 'children_lurker', 'slide',]
            if (!filterName.find(item1 => otherNodeName.includes(item1))) {
                this.setRigidBody2DType(selfNode, otherNode)
            }
            // 撞到怪物的话
            if (otherNodeName.includes('enemy')) {
                this.enemyDizzy(selfNode, otherNode)
            }
        }
    }
    enemyDizzyAttack(userNode, otherNode, playManager) {
        this.setFractionNumber(userNode, 100)
        let index = DataManager.Instance.enemyList.findIndex(item => item.node.uuid == otherNode.uuid)
        if (index != -1) {
            DataManager.Instance.enemyList.splice(index, 1)
            if (DataManager.Instance.enemyList.length == 0) {
                setTimeout(() => {
                    DataManager.Instance.player.forEach((item => {
                        item.playManager.state = PARAME_NAME_ENUM.WIN
                        if (item.playManager.direction == DIRECTION_ENUM.LEFT || item.playManager.direction == DIRECTION_ENUM.RIGHT) {
                            item.userNode.setPosition(item.defaultX - 12, item.defaultY)
                        }
                    }))
                }, getRandomNumber(500, 1000))
                if (DataManager.Instance.gameMode == GAME_MODE_ENUM.ONLINE) {
                    setTimeout(() => {
                        sendSocket(SOCKET_TYPE.SUCCESS, {})
                    }, getRandomNumber(2000, 2500))
                } else {
                    if (!DataManager.Instance.levelInfo.nextLevel) {
                        setTimeout(() => {
                            DataManager.Instance.gameElement.createClearance()
                        }, getRandomNumber(2000, 2500))
                    } else {
                        setTimeout(() => {
                            DataManager.Instance.gameElement.createAchieve()
                        }, getRandomNumber(2000, 2500))
                    }
                }
            }
        }
        createPlaceholder(otherNode)
        this.createAttackAnimation(otherNode, playManager)
    }
    // 吃掉时的位移动画
    createAttackAnimation(otherNode, playManager) {
        if (playManager) {
            let { direction } = playManager
            let { x, y } = otherNode.getPosition()
            if (direction == DIRECTION_ENUM.RIGHT) {
                x = x - 14
            } else if (direction == DIRECTION_ENUM.LEFT) {
                x = x + 14
            } else if (direction == DIRECTION_ENUM.TOP) {
                y = y - 10
            } else if (direction == DIRECTION_ENUM.BOTTOM) {
                y = y + 10
            }
            let rigidBody2D = otherNode.getComponent(RigidBody2D)
            setTimeout(() => {
                rigidBody2D.destroy()
            }, 5)
            tween(otherNode)
                .delay(.1)
                .to(.1, { position: new Vec3(x, y, 0) })
                .call(() => {
                    destroyNode(otherNode)
                })
                .start()
        } else {
            destroyNode(otherNode)
        }
    }
    // 结束触碰
    async onEndContact(self: Collider2D, other: Collider2D) {
        if (other.node.name.includes(`role`) || self.node.name.includes(`role`)) {
            let { selfNode, otherNode, otherNodeName, } = this.assortSelfAndOther({ name: "role", self, other })
            if (otherNodeName.includes('slide')) {
                let playManager = selfNode.getChildByName("role").getChildByName("userNode").getComponent(PlayManager)
                if (sys.isMobile) {
                    if (playManager.type == PLAYER_ENUM.GREEN) {
                        if (this.green_timeout) return
                        this.green_timeout = setTimeout(() => {
                            playManager.forcedWalking = false
                            let gamePlayer = selfNode.getComponent(GamePlayer)
                            gamePlayer.physicsRaycast(true)
                        }, 500)
                    } else {
                        if (this.green_timeout) return
                        this.blue_timeout = setTimeout(() => {
                            playManager.forcedWalking = false
                            let gamePlayer = selfNode.getComponent(GamePlayer)
                            gamePlayer.physicsRaycast(true)
                        }, 500)
                    }
                } else {
                    playManager.forcedWalking = false
                    let gamePlayer = selfNode.getComponent(GamePlayer)
                    gamePlayer.physicsRaycast(true)
                }
            }
            // 踩到了踩到才会触发的地刺
            if (otherNodeName.includes('children_lurker')) {
                let lurkerManager = otherNode.parent.getComponent(LurkerManager)
                let index = lurkerManager.touchNode.findIndex(item => item.uuid == selfNode.uuid)
                if (index != -1) {
                    lurkerManager.touchNode.splice(index, 1)
                }
            }
        }
    }
    setFractionNumber(selfNode, number) {
        DataManager.Instance.fraction += number
        let fraction = DataManager.Instance.operationNode.getChildByName("fraction")
        let label = fraction.getChildByName("fractionNumber").getComponent(Label)
        label.string = DataManager.Instance.fraction + ''
        const labelNode = createUINode("fractionLabel")
        labelNode.setParent(selfNode)
        labelNode.setSiblingIndex(0)
        labelNode.setPosition(0, 130)
        labelNode.addComponent(UIOpacity)
        createUILabel({ parentNode: labelNode, text: number, fontSize: 30, color: "#fbfbfd" })
        // 播放阴影变小动画
        tween(labelNode)
            .to(.2, { position: new Vec3(0, 160, 0), }, { easing: "circOut" },)
            .call(() => {
                tween(labelNode.getComponent(UIOpacity))
                    .delay(.4)
                    .to(.2, { opacity: 0 }, { easing: "circOut" },)
                    .call(() => {
                        destroyNode(labelNode)
                    })
                    .start()
            })
            .start()

    }
    // 处理怪物晕倒的逻辑
    enemyDizzy(selfNode, otherNode) {
        let enemy = otherNode.getComponent(getEnemyManager(otherNode))
        let manager = selfNode.getComponent(getPropertyManager(selfNode))
        if (enemy.avoid) {
            this.setRigidBody2DType(selfNode, otherNode)
            return
        }
        if (enemy.fly) return
        DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1241'))
        // let { x: otherX, y: otherY } = otherNode.getPosition()
        // console.log(manager.start_x, manager.start_y)
        let { x: selfX, y: selfY } = selfNode.getPosition()
        // console.log(selfX, selfY)
        let direction
        if (manager.start_x == selfX && manager.start_y == selfY) {
            direction = manager.user_direction
        } else {
            if (manager.start_x == selfX) {
                if (manager.start_y > selfY) {
                    console.log("上")
                    direction = "top"
                } else {
                    console.log("下")
                    direction = "bottom"
                }
            } else {
                if (manager.start_x > selfX) {
                    console.log("右")
                    direction = "right"
                } else {
                    console.log("左")
                    direction = "left"

                }
            }
        }
        enemy.perpetrator = selfNode
        let list = enemy.getEmptyPhysicsArr()
        if (list.length > 0) {
            enemy.dizzy_direction = direction
            enemy.dizzy = true
        } else {
            let playManager = manager.parent_node.getComponent(PlayManager)
            this.enemyDizzyAttack(manager.parent_node, otherNode, playManager)
        }
    }

    // 把指定名称的node赋值给selfnode
    assortSelfAndOther({ name, self, other }) {
        let selfNode
        let selfNodeName
        let otherNode
        let otherNodeName
        if (self.node.name.includes(name)) {
            selfNode = self.node;
            otherNode = other.node;
            selfNodeName = self.node.name;
            otherNodeName = other.node.name;
        } else {
            selfNode = other.node;
            otherNode = self.node;
            selfNodeName = other.node.name;
            otherNodeName = self.node.name;
        }
        return {
            selfNode,
            selfNodeName,
            otherNode,
            otherNodeName,
        }
    }
    // 砖块破碎动画执行结束
    onBrickFinished(type: Animation.EventType, state) {
        console.log(state._targetNode.parent, "state._targetNode.parent")
        createPlaceholder(state._targetNode)
        destroyNode(state._targetNode)
        let index = this.brickAttackList.findIndex(item => item.uuid == state._targetNode.uuid)
        if (index != -1) {
            this.brickAttackList.splice(index, 1)
        }
    }
    // 把弹性系数变为0
    setBoxRestitution(node) {
        setTimeout(() => {
            const boxCollider2D = node.getComponent(BoxCollider2D)
            boxCollider2D.restitution = 0
            boxCollider2D.apply()
        }, 5)
    }
    // 播放砖头破碎动画
    playBrickAttack(node) {
        let index = this.brickAttackList.findIndex(item => item.uuid == node.uuid)
        if (index == -1) {
            this.brickAttackList.push(node)
            // 播放破碎动画，动画结束后销毁元素
            const animation = node.getComponent(Animation)
            animation.play()
            animation.on(
                Animation.EventType.FINISHED,
                this.onBrickFinished,
                this
            );
        }
    }
    // 把刚体变为静态刚体
    setRigidBody2DType(selfNode, otherNode) {
        let { x: otherX, y: otherY } = otherNode.getPosition()
        let { x: selfX, y: selfY } = selfNode.getPosition()
        let manager = selfNode.getComponent(getPropertyManager(selfNode))
        if (otherNode.name.includes("role") && manager.spring_back == true) {
            console.log("回弹撞到了角色,角色应该死亡")
            otherNode.getComponent(GamePlayer).characterDeath()
            return
        }
        if (otherNode.name.includes("role")) return
        let direction
        if (otherX == selfX) {
            if (selfY > otherY) {
                direction = DIRECTION_ENUM.TOP
            } else {
                direction = DIRECTION_ENUM.BOTTOM
            }
        } else {
            if (parseInt(otherY + 30) >= selfY - 3 || parseInt(otherY + 30) <= selfY - 3) {
                if (selfX > otherX) {
                    direction = DIRECTION_ENUM.RIGHT
                } else {
                    direction = DIRECTION_ENUM.LEFT
                }
            }
        }
        // 如果碰到了砖头,就把砖头砸碎
        if (otherNode.name.includes('brick')) {
            this.playBrickAttack(otherNode)
            DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1231'))
        }
        if (selfNode.name.includes('brick')) {
            this.playBrickAttack(selfNode)
            DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1231'))
        }
        // 碰到炸弹就播放倒计时
        if (otherNode.name.includes(`bomb`)) {
            otherNode.getComponent(BombManager).getComponent(ExplosionTimingManager).playBombAnimation()
        }
        // 碰到果冻会回弹
        if (!selfNode.name.includes('brick') && !otherNode.name.includes('brick')) {
            if (otherNode.name.includes("jelly") || selfNode.name.includes("jelly")) {
                manager.touch_jelly = true
                manager.spring_number = manager.spring_number + 1
            }
            if (otherNode.name.includes("jelly")) {
                const animation = otherNode.getComponent(Animation)
                animation.play()
            }
        }
        if (otherNode.name.includes("jelly")) {
            DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1235'))
        }
        if (selfNode.name.includes("jelly")) {
            DataManager.Instance.audioMgr.playOneShot(DataManager.Instance.audio.find(item => item.name == '1227'))
        }
        manager.getNearPosition(direction)
    }
    // 获取道具的manager
    // getPropertyManager(node) {
    //     if (node.name.includes('stone')) {
    //         return StoneManager
    //     } else if (node.name.includes('bomb')) {
    //         return BombManager
    //     } else if (node.name.includes('jelly')) {
    //         return JellyManager
    //     } else if (node.name.includes('heavy')) {
    //         return HeavyManager
    //     } else if (node.name.includes('brick')) {
    //         return BrickManager
    //     }
    // }

}


